exports.TrashUI = GL2.Sprite.subclass(
{
    classname: 'TrashUI',
    
    initialize: function(model) 
    {
    	this._modelObj = model;
    },
	
	createView: function()
	{	
		this.addImage();
		this.handleTouches();
	},
	
	addImage: function()
	{
		var trashImagePath = this.getRandomTrashImagePath();	
	
		this.setImage(trashImagePath, [TCUtil.getAdjustedX(25), TCUtil.getAdjustedY(25)], [0, 0]);
	},
	
	getRandomTrashImagePath: function()
	{
		var randomTrashType = Math.round(Math.random()*(NO_OF_TRASH_IMAGES-1));
		var trashPath = this.getBaseResourcePath() + "trash"+randomTrashType+".png";
		
		return trashPath;
	},
	
	handleTouches: function() 
	{
		this._touchTarget = new GL2.TouchTarget();
		this._touchTarget.setSize(TCUtil.getAdjustedX(40),TCUtil.getAdjustedX(40));
		this._touchTarget.setAnchor(0, 0);
		this._touchTarget.setPosition(this.getPosition().getX() - TCUtil.getAdjustedX(8) , this.getPosition().getY() - TCUtil.getAdjustedX(8));
		this._touchTarget.getTouchEmitter().addListener(MMGameLayer.getMallContainer().getMallUI()._touchHandler, this.onTouch.bind(this),10);
		this._touchTarget.setDepth(100000);
		this.addChild(this._touchTarget);
	},
	
	onTouch: function(touch)
	{
		MMGameLayer.getMallUI().getTouchHandler().onTouch(touch);
		switch(touch.getAction())
		{
			case touch.Action.Start:
				this.onTrashTouch();
                return true;
			break;
            
            case touch.Action.End:
            {				
                this._isPanned = false;
            }
			break;
			
            
            case touch.Action.Move:

				this._isPanned = true;

			break;
		}		
	},
	
	onTrashTouch: function()
	{
		if(DatabaseInterface._isVisitingNeighbor)
		{
			if(TutorialManager.getHasCompletedTutorial())
			{
				var friend = MMFriendManager.getVisitingFriendObj();
				var serverTime = MMGameState.getServerTime();
				var currentActions = MMFriendActionManager.getFriendTrashActionState(friend.id);
				if(currentActions)
				{				
					var timeToReset = parseInt(currentActions[1]) + SECS_IN_ONE_DAY - parseInt(serverTime);
					var actionCount = +currentActions[2];
					
					if(timeToReset < 0)
					{
						actionCount = 0;
					}
					
					if(actionCount >= MAX_FRIEND_TRASH_COLLECT)
					{
						var alertBox = UIFactory.getAlertBox(Core.Localization.getString("MESSAGE"), GALocalizationHandler.getRelativeString(Core.Localization.getString("REACHED_LIMIT_FOR_HELPING_FRIEND"),[friend.displayName]), ["Ok"], this);
						return;
					}
					else
					{
						var rewardAmount = TRASH_COLLECT_REWARD;
						MMFriendActionManager.setFriendCoinCollectedCount(+rewardAmount);
						actionCount++;
						MMFriendActionManager.saveFriendTrashActionState([""+friend.id,serverTime,actionCount]);
					}
				
				}
				else
				{
					MMFriendActionManager.saveFriendTrashActionState([""+friend.id,serverTime,1]);
				}
			}
			var rewardAmount = TRASH_COLLECT_REWARD;
			MMFriendActionManager.setFriendCoinCollectedCount(+rewardAmount);
		}

		MMSoundManager.playEffect(TRASH_COLLECT_SOUND);
		if(TutorialManager.getHasCompletedTutorial())
		{
			TrashHandler.trashTappedForRemoval(this);
		}
		else
		{
			if(TutorialManager.getCurrentTutorialStep() == 11 || (TutorialManager.getCurrentTutorialStep() == 12 && DatabaseInterface._isVisitingNeighbor))
			{
				TrashHandler.trashTappedForRemoval(this);					
			}
		}

	},
			
	getBaseResourcePath: function()
	{
		var path = "./Content/images/trashimages/";
		
		return path;
	},
								   
	destroy: function()
    {

    },
});
